

import { configureStore,combineReducers } from "@reduxjs/toolkit";
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';

import counterReducer from './modules/counterStore'
import userReducer from './modules/userStore'

// 配置持久化
const persistConfig = {
  key: 'root',
  storage,
};

// 合并reducer
var all = combineReducers({
  counter: counterReducer,
  user: userReducer
})

// 获取持久化配置项
function getPersistConfig(key){
  return {
    key,
    storage,
  }
}
const store = configureStore({
  reducer:persistReducer(persistConfig,all),
  middleware: (getDefaultMiddleware) => getDefaultMiddleware({
    serializableCheck: false
 })
})

// 导出 persistor 对象以帮助持久化
export const persistor = persistStore(store);

export default store